package kosta.service;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import kosta.model.dao.MemberDAO;
import kosta.model.vo.ListVO;
import kosta.model.vo.MemberVO;
import kosta.model.vo.MessageVO;
import kosta.model.vo.PagingBean;
import kosta.model.vo.SearchVO;

import org.springframework.stereotype.Service;

@Service
public class MemberServiceImpl implements MemberService {

	@Resource(name = "memberDAOImpl")
	private MemberDAO memberDAO;

	@Override
	public String findMyPassword(MemberVO vo) {
		return memberDAO.findMyPassword(vo);
	}

	@Override
	public MemberVO login(MemberVO vo) {
		// TODO Auto-generated method stub
		return memberDAO.login(vo);
	}

	@Override
	public String findMyId(MemberVO vo) {
		return memberDAO.findMyId(vo);
	}

	@Override
	public void registerMember(MemberVO vo) {
		memberDAO.registerMember(vo);

	}

	@Override
	public int idDuplCheck(String id) {
		return memberDAO.idDuplCheck(id);
	}

	@Override
	public MemberVO registerResult(String id) {
		return memberDAO.registerResult(id);
	}

	@Override
	public int emailDuplCheck(String email) {

		return memberDAO.emailDuplCheck(email);
	}

	@Override
	public ListVO getMyBidList(SearchVO svo) {
		int total = memberDAO.getMyBidListCount(svo);
		System.out.println("입찰내역 수 : " + total);
		List list = memberDAO.getMyBidList(svo);
		PagingBean pagingBean = new PagingBean(total, svo.getPageNo());
		return new ListVO(list, pagingBean);
	}

	@Override
	public ListVO getMyAuctionRegisterHistory(SearchVO svo) {
		int total = memberDAO.getMyAuctionRegisterHistoryCount(svo);
		System.out.println("입찰내역 수 : " + total);
		List list = memberDAO.getMyAuctionRegisterHistory(svo);
		PagingBean pagingBean = new PagingBean(total, svo.getPageNo());
		return new ListVO(list, pagingBean);
	}

	@Override
	public void memberLeave(MemberVO mvo) {
		memberDAO.messageLeave(mvo);
		memberDAO.memberLeave(mvo);	
	}

	@Override
	public void updateMember(MemberVO mvo) {
		memberDAO.updateMember(mvo);
	}

	@Override
	public void sendMessage(MessageVO msvo) {
		memberDAO.sendMessage(msvo);
	}

	@Override
	public ListVO getMyMessageList(SearchVO svo) {
		int total = memberDAO.getMyMessageCount(svo);
		System.out.println("입찰내역 수 : " + total);
		List list = memberDAO.getMyMessageList(svo);
		PagingBean pagingBean = new PagingBean(total, svo.getPageNo());
		return new ListVO(list, pagingBean);
	}

	@Override
	public MessageVO showMessageContent(int messageNo, String flag) {
		if (flag.equals("receive")) {
			memberDAO.updateReadCheck(messageNo);
		}
		return memberDAO.showMessageContent(messageNo);
	}

	@Override
	public void deleteMessage(int messageNo, String flag) {
		HashMap map = new HashMap();
		map.put("messageNo", messageNo);
		map.put("flag", flag);
		memberDAO.deleteMessage(map);
		MessageVO msvo = memberDAO.showMessageContent(messageNo);
		if (msvo.getSendMemberDeleteCheck() == 1
				&& msvo.getReceiveMemberDeleteCheck() == 1) {
			memberDAO.deleteMessageDB(messageNo);
		}
	}

	@Override
	public MemberVO memberLogin(MemberVO vo) {		
		return memberDAO.memberLogin(vo);
	}

}
